package org.nstack.network.service.portforwarding;

import org.springframework.http.HttpMethod;
import org.nstack.header.identity.Action;
import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.nstack.header.notification.ApiNotification;
import org.nstack.header.rest.RestRequest;
import org.nstack.header.vm.VmNicVO;


@Action(category = PortForwardingConstant.ACTION_CATEGORY)
@RestRequest(
        path = "/port-forwarding/{ruleUuid}/vm-instances/nics/{vmNicUuid}",
        method = HttpMethod.POST,
        responseClass = APIAttachPortForwardingRuleEvent.class
)
public class APIAttachPortForwardingRuleMsg extends APIMessage {

    @APIParam(resourceType = PortForwardingRuleVO.class, checkAccount = true, operationTarget = true)
    private String ruleUuid;

    @APIParam(resourceType = VmNicVO.class, checkAccount = true, operationTarget = true)
    private String vmNicUuid;

    public String getRuleUuid() {
        return ruleUuid;
    }

    public void setRuleUuid(String ruleUuid) {
        this.ruleUuid = ruleUuid;
    }

    public String getVmNicUuid() {
        return vmNicUuid;
    }

    public void setVmNicUuid(String vmNicUuid) {
        this.vmNicUuid = vmNicUuid;
    }
 
    public static APIAttachPortForwardingRuleMsg __example__() {
        APIAttachPortForwardingRuleMsg msg = new APIAttachPortForwardingRuleMsg();
        msg.setVmNicUuid(uuid());
        msg.setRuleUuid(uuid());
        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                if (evt.isSuccess()) {
                    ntfy("Attached port forwarding Rule[uuid:%s]",ruleUuid).resource(vmNicUuid,VmNicVO.class.getSimpleName())
                            .messageAndEvent(that, evt).done();
                }
            }
        };
    }

}
